
import Minput from './input';
import Mpassword from './password';

export default function Search(prop:any) {
  function submit(event:any){
	event.preventDefault()
	const formData = new FormData(event.target);
	let ob:any = {}
	prop.formConfig?.list.map((e:any)=>{
		ob[e.prop] = formData.get(e.prop)		
	})
    prop.formConfig.clfn && prop.formConfig.clfn(ob)
  }
  const listd = prop.formConfig?.list.map((e:any)=>{
  		  if(e.type=='input'){
  			  return <Minput key={e.prop}
  		      width={e.widht || 'md'}
  		      name={e.prop}
  		      label={e.label}
  		      tooltip={e.tooltip}
  		      placeholder={e.placeholder}
  		    ></Minput>
  		  }
		  if(e.type=='password'){
		    			  return <Mpassword key={e.prop}
		     config={e}
		    ></Mpassword>		
		  }	    		  
  	  })
  return (
    <form onSubmit={submit}>		
		{listd}
		{prop.children}
    </form>
  );
}